package com.qyc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qyc.pojo.Log;
import com.qyc.service.LogService;
import com.qyc.mapper.LogMapper;
import com.qyc.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
* @author qinyc
* @description 针对表【base_log(日志信息表)】的数据库操作Service实现
* @createDate 2023-06-21 16:54:07
*/
@Service
public class LogServiceImpl extends ServiceImpl<LogMapper, Log>
    implements LogService{
    //注入日志Mapper层对象
    @Autowired
    private LogMapper logMapper;

    /**
     * @Author qinyc
     * @Description  分页多条件查询日志信息
     * @version: v1.0
     * @Date 17:39 2023/6/21
     **/
    @Override
    public ResponseResult logPage(Integer pageNum, Integer pageSize, String originalIp) {
        //开启分页插件
        PageHelper.startPage(pageNum,pageSize);
        //查询数据
        //创建条件选择器
        LambdaQueryWrapper<Log> logLambdaQueryWrapper = new LambdaQueryWrapper<>();
        //如果IP存在根据IP查询
        logLambdaQueryWrapper.eq(StringUtils.hasText(originalIp),Log::getLogHost,originalIp);
        //根据条件选择器查询符合条件的数据
        List<Log> logs = logMapper.selectList(logLambdaQueryWrapper);
        //将查询出来的信息封装在PageInfo对象里面
        PageInfo<Log> logPageInfo = new PageInfo<>(logs);
        //返回统一格式的响应
        return ResponseResult.success(logPageInfo);
    }
}




